/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "update_lite_ipc_process.h"

#include "thread_adapter.h"
#include "ipc_skeleton.h"
#include "securec.h"
#include "hilog/log.h"


IpcIo *libApireply = NULL;



uint32_t libApicallback(int nownum)
{
    if(libApireply != NULL)
    {
        WriteUint32(libApireply, 0);
        WriteUint32(libApireply, nownum);
    }
    return 1;
}

static void *libApiThread(void *argv)
{
    HILOG_INFO(LOG_CORE, "libApiThread....[%d]", pthread_self());
    int nownum = 0;
    while (true) {
        //sleep(3);
        HILOG_INFO(LOG_CORE, "libApiThread....[%d]  - ----- nownum = %d", pthread_self(), nownum++);
        libApicallback(nownum);
        sleep(1); break;
        //if(nownum > 3) break;
    }
    printf("libApiThread! --  end\n");

    return NULL;
}

int32_t UpdateLiteXxxApi_libApi(IUnknown *iUnknown, IpcIo *req, IpcIo *reply)
{
    HILOG_INFO(LOG_CORE, "update_lite_ipc_process.c ---- UpdateLiteXxxApi_libApi-----1");
    int mreturn = 6;
    //WriteUint32(reply, 0);
    //WriteUint32(reply, mreturn);
    if(libApireply == NULL)
    {
        libApireply = reply;
    }
    libApicallback(mreturn);
    //ThreadAttr attr = {"collector thread", 1024, 2, 0, 0};
    //ThreadId threadId = (ThreadId)THREAD_Create(libApiThread, NULL, &attr);
    sleep(2);
    return mreturn;
}